<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
 <head>
  <title>inputEx - ListField Usage</title>

<!-- YUI CSS -->
<link rel="stylesheet" type="text/css" href="../lib/yui/reset-fonts/reset-fonts.css">
<link rel="stylesheet" type="text/css" href="../lib/yui/container/assets/container.css"> 
<link rel="stylesheet" type="text/css" href="../lib/yui/assets/skins/sam/skin.css">

<!-- InputEx CSS -->
<link type='text/css' rel='stylesheet' href='../css/inputEx.css' />

<!-- Demo CSS -->
<link rel="stylesheet" type="text/css" href="css/demo.css"/>
<link rel="stylesheet" type="text/css" href="css/dpSyntaxHighlighter.css">

 </head>

 <body>

<h1>inputEx - ListField Usage</h1>

<!-- YUI Library -->
<script type="text/javascript" src="../lib/yui/utilities/utilities.js"></script>
<script type="text/javascript" src="../lib/yui/container/container-min.js"></script>
<script type="text/javascript" src="../lib/yui/json/json-min.js"></script>

<!-- InputEx -->
<script src="../js/inputex.js"  type='text/javascript'></script>
<script src="../js/mixins/choice.js"  type='text/javascript'></script>
<script src="../js/Field.js"  type='text/javascript'></script>
<script src="../js/fields/StringField.js"  type='text/javascript'></script>
<script src="../js/fields/UrlField.js"  type='text/javascript'></script>
<script src="../js/fields/ListField.js"  type='text/javascript'></script>
<script src="../js/fields/SelectField.js"  type='text/javascript'></script>

<!-- only for the last example -->
<script src="../js/Group.js"  type='text/javascript'></script>
<script src="../js/Form.js"  type='text/javascript'></script>
<script src="../js/widgets/Button.js"  type='text/javascript'></script>



<script src="js/dpSyntaxHighlighter.js"></script>
<script src="inputex-examples.js"></script>


<!-- Example 1 -->
<div class='exampleDiv'>
 <h2>Basic ListField creation</h2>
 <p>Use the following code to create a basic inputEx ListField.</p>
 <div class='demoContainer' id='container1'></div>
 <div class='codeContainer'>
  <textarea name="code" class="JScript">
		var field = new inputEx.ListField({
			name: 'websiteUrl', 
			listLabel: 'Websites',
			elementType: {type: 'url'},
			value: ['http://www.neyric.com', 'http://www.ajaxian.com', 'http://www.google.com', 'http://www.yahoo.com'], 
			parentEl: 'container1'
		});
		var button = inputEx.cn('button', null, null, 'getValue()');
		YAHOO.util.Dom.get('container1').appendChild(button); 
		YAHOO.util.Event.addListener(button, 'click', function() { alert( YAHOO.lang.JSON.stringify(field.getValue())); });  
		var button2 = inputEx.cn('button', null, null, 'setValue()');
		YAHOO.util.Dom.get('container1').appendChild(button2); 
		YAHOO.util.Event.addListener(button2, 'click', function() {
			field.setValue(['http://www.sncf.com',
											'http://www.clicrdv.com',
											'http://www.neyric.com',
											'http://javascript.neyric.com/wireit']);			
		});
		var button3 = inputEx.cn('button', null, null, 'Clear');
		YAHOO.util.Dom.get('container1').appendChild(button3); 
		YAHOO.util.Event.addListener(button3, 'click', function() {
			field.setValue([]);
		});
	
  </textarea>
 </div>
</div>




<!-- Example 2 -->
<div class='exampleDiv'>
 <h2>Sortable list</h2>
 <p>Example for the sortable ListField</p>
 <div class='demoContainer' id='container2'></div>
 <div class='codeContainer'>
  <textarea name="code" class="JScript">
		
		var field2 = new inputEx.ListField({
			listLabel: 'Reorder example',
			elementType: {type: 'string'},
			value: ['one', 'two', 'three', 'four'], 
			parentEl: 'container2',
			sortable: true
		});
		var buttonGetValue = inputEx.cn('button', null, null, 'getValue()');
		YAHOO.util.Dom.get('container2').appendChild(buttonGetValue); 
		YAHOO.util.Event.addListener(buttonGetValue, 'click', function() { 
			alert( YAHOO.lang.JSON.stringify(field2.getValue())); 
		});
	
  </textarea>
 </div>
</div>





<!-- Example 3 -->
<div class='exampleDiv'>
 <h2>Updated event</h2>
 <p>How to listen to the updated event :</p>
 <div class='demoContainer' id='container3'></div>
 <div class='codeContainer'>
  <textarea name="code" class="JScript">
		var field3 = new inputEx.ListField({parentEl: 'container3', value: ["one", "two", "three", "four"], sortable: true });
		var logDiv = inputEx.cn('div', null, null, "Log :");
		YAHOO.util.Dom.get('container3').appendChild(logDiv);
		field3.updatedEvt.subscribe(function(e,params) {
			var value = params[0];
			logDiv.innerHTML += "Updated at "+(new Date())+" with value "+YAHOO.lang.JSON.stringify(value);
		});
  </textarea>
 </div>
</div>



<!-- Example 4 -->
<div class='exampleDiv'>
 <h2>Use buttons instead of links</h2>
 <p>Use buttons :</p>
 <div class='demoContainer' id='container4'></div>
 <div class='codeContainer'>
  <textarea name="code" class="JScript">
		new inputEx.ListField({
			listLabel: 'Websites',
			elementType: {
				type: 'select', 
				choices:  ['http://www.neyric.com', 'http://www.ajaxian.com', 'http://www.google.com', 'http://www.yahoo.com', 'http://javascript.neyric.com/blog', 'http://javascript.neyric.com/wireit', 'http://neyric.github.com/inputex']
			},
			value: ['http://www.neyric.com', 'http://www.ajaxian.com', 'http://www.google.com', 'http://www.yahoo.com'], 
			parentEl: 'container4',
			useButtons: true // set to true to display buttons instead of links
		});
  </textarea>
 </div>
</div>



<!-- Example 5 -->
<div class='exampleDiv'>
 <h2>Set maximum/minimum number of items</h2>
 <p>Use the maxItems and minItems options :</p>
 <div class='demoContainer' id='container5'></div>
 <div class='codeContainer'>
  <textarea name="code" class="JScript">
		new inputEx.ListField({
			listLabel: 'Websites',
			maxItems: 4,
			minItems: 1,
			elementType: {
				type: 'select',
				choices:  ['http://www.neyric.com', 'http://www.ajaxian.com', 'http://www.google.com', 'http://www.yahoo.com', 'http://javascript.neyric.com/blog', 'http://javascript.neyric.com/wireit', 'http://neyric.github.com/inputex']
			},
			value: ['http://www.neyric.com', 'http://www.ajaxian.com', 'http://www.google.com', 'http://www.yahoo.com'], 
			parentEl: 'container5',
			useButtons: true 
		});
  </textarea>
 </div>
</div>




<!-- Example 6 -->
<div class='exampleDiv'>
 <h2>Field names</h2>
 <p>The names are automatically set on sub-fields, so that standard forms can work. Click the button and check the URL</p>
 <div class='demoContainer' id='container6'></div>
 <div class='codeContainer'>
  <textarea name="code" class="JScript">	
    new inputEx.Form( {
			fields: [
			{
				name: 'firstVar',
				label: "First variable",
				value: "my-custom-value"
			},
			{
				type: 'list',
				label: "My Array",
				maxItems: 4,
				minItems: 1,
				elementType: {type: 'string'},
				value: ['this', 'is', 'a', 'test'],
				name: 'myarray',
				useButtons: true ,
				sortable: true
			}],
      buttons: [{type: 'submit', value: 'Test to send the GET request'}],
			method: 'GET',
			parentEl: 'container6'
		});
  </textarea>
 </div>
</div>



 </body>
</html>